package com.fourth.controller.api;


import com.fourth.service.DepositService;
import com.ljx.entity.Deposit;
import com.ljx.vo.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.*;

/**
 * @author xiaoZhu
 * @version 1.0
 * @date 2023/2/27 11:44
 */
@Api(value = "commodity/api", tags = {""})
@RestController
@RequestMapping("commodity/api")

public class ApiDepositController {


    @Autowired
    private DepositService depositService;

    /**
     * 查询全部储存方式
     * @param currentPage
     * @param pageSize
     * @return
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "int", name = "currentPage", value = "", required = true),
            @ApiImplicitParam(paramType = "query", dataType = "int", name = "pageSize", value = "", required = true)
    })
    @ApiOperation(value = "查询全部储存方式", notes = "查询全部储存方式", httpMethod = "POST")
    @PostMapping("/select")
    public Result selectAll(
            @RequestParam(defaultValue = "1") Integer currentPage,
            @RequestParam(defaultValue = "5") Integer pageSize,
            @RequestBody Deposit deposit
    ){

        return depositService.selectAll(currentPage, pageSize,deposit);
    }

    /**
     * 修改审核状态
     * @param deposit
     * @return
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "Deposit", name = "deposit", value = "", required = true)
    })
    @ApiOperation(value = "修改审核状态", notes = "修改审核状态", httpMethod = "POST")
    @PostMapping("/update")
    @ResponseBody
    public Result updateById(@RequestBody Deposit deposit){
        System.out.println("deposit = " + deposit);
        boolean b = depositService.updateById(deposit);
        if (b==true){
            return new Result(200,"修改成功");
        }else {
            return new Result(500,"修改失败");
        }
    }

    /**
     * 根据Id删除储存方式
     * @param Id
     * @return
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "int", name = "Id", value = "", required = true)
    })
    @ApiOperation(value = "根据Id删除储存方式", notes = "根据Id删除储存方式", httpMethod = "POST")
    @PostMapping("/delece")
    public Result delece(Integer Id){
        boolean b = depositService.removeById(Id);
        if (b==true){
            return new Result(200,"删除成功");
        }else {
            return new Result(500,"删除失败");
        }
    }

}
